package hero.main;

import helpers.StaticHelper;

import java.util.ArrayList;

import sqlHelp.DatabaseHelper;
import android.app.ListActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import customWidgets.HeroAdapter;


public class HeroList extends ListActivity {
	/**
	 * Class members
	 */
	ListView lv;
	DatabaseHelper dbHelper = null;
	/**
	 * Class members
	 *
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	

    	dbHelper = new DatabaseHelper(this);
    	SQLiteDatabase myDb = dbHelper.getWritableDatabase();
    	ArrayList<String> mainList = dbHelper.getAllOfColumn("HeroName", this, myDb);
    	ArrayList<String> imageList = dbHelper.getAllOfColumn("HeroAvatar", this, myDb);
    	
    	HeroAdapter arrayAdapter =      
    	         new HeroAdapter(this, R.layout.hero_list, StaticHelper.heroMaker(mainList, imageList, this));
    	 
    	setListAdapter(arrayAdapter);
    	
    	lv = getListView();
    	lv.setTextFilterEnabled(true);
    	lv.setBackgroundDrawable(getResources().getDrawable(R.drawable.listback));
    	lv.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					switch(arg2){
					default:
						Intent i = new Intent(HeroList.this, HeroTabActivity.class);
						startActivity(i);
						
						
					}
					
				}
 		  });
    	
    	
    	
    	
    }
}